<template>
	<view>
		<u-form labelPosition="left" :model="form" ref="uForm" label-width="200rpx">
			<!-- 	<view
				style="display: flex;flex-direction: row;
				justify-content: space-between;
				align-items: center;"
			>
				<text>物料编码：</text>
				<u-input v-model="form.name" placeholder="请选择" :border="border" disabled></u-input>
				<u-icon name="arrow-down-fill" @click="navTo('/pages/sys/home/components/work_bench/public/inventory_list')"></u-icon>
			</view> -->
			<view
				style="display: flex;flex-direction: row;
				justify-content: space-between;
				align-items: center;"
			>
				<text>产品名称：</text>
				<picker @change="pickerChange($event, array)" :value="index" :range-key="'itemName'" :range="array">
					<view>{{ array[index].itemName }}</view>
				</picker>
				<u-icon name="arrow-down-fill"></u-icon>
			</view>
			<u-form-item label="产品编码:" prop="itemCode" borderBottom><u-input v-model="form.itemCode" placeholder="" :border="border" disabled></u-input></u-form-item>
			<u-form-item label="规格型号:" prop="unitOfMeasure" borderBottom><u-input v-model="form.unitOfMeasure" placeholder="" :border="border" disabled></u-input></u-form-item>
			<u-form-item label="单位:" prop="specification" borderBottom><u-input v-model="form.specification" placeholder="" :border="border" disabled></u-input></u-form-item>
			<u-form-item label="仓库:" prop="warehouseName" borderBottom><u-input v-model="form.warehouseName" placeholder="" :border="border" disabled></u-input></u-form-item>
			<u-form-item label="库区:" prop="locationName" borderBottom><u-input v-model="form.locationName" placeholder="" :border="border" disabled></u-input></u-form-item>
			<u-form-item label="库位:" prop="areaName" borderBottom><u-input v-model="form.areaName" placeholder="" :border="border" disabled></u-input></u-form-item>
			<u-form-item label="批次号:" prop="batchCode" borderBottom><u-input v-model="form.batchCode" placeholder="" :border="border"></u-input></u-form-item>
			<u-form-item label="退货数量:" prop="quantityRted" borderBottom>
				<u-input v-model="form.quantityRted" placeholder="请输入退货数量" :border="border"></u-input>
			</u-form-item>
			<u-form-item label="备注:" prop="remark" borderBottom><u-input v-model="form.remark" placeholder="" :border="border"></u-input></u-form-item>
		</u-form>
		<u-row gutter="32" class="bottom-box" justify="center">
			<u-col span="10">
				<view><u-button type="primary" shape="circle" @click="handleSave()">保存</u-button></view>
			</u-col>
		</u-row>
	</view>
</template>
<script>
export default {
	data() {
		return {
			form: {
				lineId: null,
				rtId: null,
				materialStockId: null,
				itemId: null,
				itemCode: null,
				itemName: null,
				specification: null,
				unitOfMeasure: null,
				quantityRted: null,
				quantityMax: null,
				batchCode: null,
				warehouseId: null,
				warehouseCode: null,
				warehouseName: null,
				locationId: null,
				locationCode: null,
				locationName: null,
				areaId: null,
				areaCode: null,
				areaName: null,
				remark: null,
				attr1: null,
				attr2: null,
				attr3: null,
				attr4: null,
				createBy: null,
				createTime: null,
				updateBy: null,
				updateTime: null
			},
			border: false,
			rtId: null, //退货单ID
			// 物料参数
			param: {
				pageNum: 1,
				pageSize: 10
			},
			// 物料列表
			array: [{ itemName: '' }],
			index: 0
		};
	},
	onLoad(options) {
		// const ID = JSON.parse(options.params);
		// this.rtId = ID.recptId;
		// this.lineId = ID.lineId;
		this.rtId = parseInt(uni.getStorageSync('rtId'));
		this.form.rtId = this.rtId;
		console.log(this.rtId);
		uni.removeStorageSync('rtId');
		this.getMaterial();
	},
	onReady() {
		//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
		this.$refs.uForm.setRules(this.rules);
	},
	methods: {
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		// 物料选择事件
		pickerChange(e, storage) {
			console.log(e, storage);
			this.index = e.target.value;
			this.form = storage[this.index];
		},
		// 获取存库物资
		getMaterial() {
			this.$u.api.inventoryInquiry.getInventoryList(this.param).then(res => {
				console.log(res);
				// this.materialList = res.rows;
				this.array = res.rows;
			});
		},
		// 保存
		handleSave() {
			this.form.quantityRted = parseInt(this.form.quantityRted);
			this.$u.api.saleBack
				.handleSaleBackAddLine(this.form)
				.then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '新增成功',
							duration: 1000
						});
						uni.navigateTo({
							url: '/pages/sys/home/components/work_bench/sale-back/sale_back?params=' + this.rtId
						});
					}
				})
				.catch(err => {
					console.log(err);
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.u-form {
	padding: 0 40rpx;
}
.buttons {
	margin-top: 50rpx;
	display: flex;
	justify-content: space-between;
}
</style>
